package com.zz.cinema.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.zz.cinema.dao.ITS_CustomerDao;
import com.zz.cinema.domain.TS_Customer;
import com.zz.cinema.util.PageList;

@Repository("customerDao")
public class TS_CustomerDaoImpl extends TS_BaseDaoImpl5 implements ITS_CustomerDao {


	@Override
	public boolean deleteCustomer(int customerId) {
		TS_Customer customer = null;
		try {
			customer = (TS_Customer) findList("from TS_Customer c where c.customerId = ?", customerId).get(0);
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		getSession().delete(customer);
		return true;
	}

	@Override
	public TS_Customer getCustomer(int customerId) {
		
		TS_Customer customer = null;
		try {
			customer = (TS_Customer) findList("from TS_Customer c where c.customerId = ?", customerId).get(0);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
		return customer;
	}

	@Override
	public PageList<TS_Customer> getPage(int page) {
		
		
		int rows = 5;
		PageList<TS_Customer> pageList = findPageList("from TS_Customer c order by c.customerId asc", page, rows);
		return pageList;
	}

	@Override
	public boolean saveCustomer(TS_Customer customer) {

		saveObject(customer);
		return true;
	}

	@Override
	public TS_Customer updateCustomer(TS_Customer customer) {
		
		updateObject(customer);
		return customer;
	}
	
}
